package com.yunchen.ishop;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DurationFormatUtils;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2015/5/15.
 */
public class Main {

    public static void main(String[] args) {

        String phone = "13476129089";
        StringBuilder phoneBuilder = new StringBuilder();
        phoneBuilder.append(StringUtils.substring(phone, 0, 3)).append(" ");
        phoneBuilder.append(StringUtils.substring(phone, 3, 7)).append(" ");
        phoneBuilder.append(StringUtils.substring(phone, 7)).append(" ");
        System.out.println(phoneBuilder.toString());


        Calendar calendar = Calendar.getInstance();
        Date endDate = calendar.getTime();

        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
        Date startDate = calendar.getTime();

        String startDateStr = DateFormatUtils.format(startDate,
                "yyyy-MM-dd HH:mm:ss");
        String endDateStr = DateFormatUtils.format(endDate,
                "yyyy-MM-dd HH:mm:ss");

        String durationByMonth = DurationFormatUtils.formatPeriod(
                startDate.getTime(), endDate.getTime(), "M");
        String durationByDay = DurationFormatUtils.formatPeriod(
                startDate.getTime(), endDate.getTime(), "m");

        System.out.println("start time : " + startDateStr);
        System.out.println("end time : " + endDateStr);
        System.out.println("时间间隔 (月): " + durationByMonth);
        System.out.println("时间间隔 (分钟): " + durationByDay);
    }
}
